package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ElderlyReferral;
import com.ruoyi.system.service.IElderlyReferralService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 老人送诊
Controller
 * 
 * @author ruoyi
 * @date 2021-08-03
 */
@RestController
@RequestMapping("/system/referral")
public class ElderlyReferralController extends BaseController
{
    @Autowired
    private IElderlyReferralService elderlyReferralService;

    /**
     * 查询老人送诊
列表
     */
//    @PreAuthorize("@ss.hasPermi('system:referral:list')")
    @GetMapping("/list")
    public TableDataInfo list(ElderlyReferral elderlyReferral)
    {
        startPage();
        List<ElderlyReferral> list = elderlyReferralService.selectElderlyReferralList(elderlyReferral);
        return getDataTable(list);
    }

    /**
     * 导出老人送诊
列表
     */
//    @PreAuthorize("@ss.hasPermi('system:referral:export')")
    @Log(title = "老人送诊", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ElderlyReferral elderlyReferral)
    {
        List<ElderlyReferral> list = elderlyReferralService.selectElderlyReferralList(elderlyReferral);
        ExcelUtil<ElderlyReferral> util = new ExcelUtil<ElderlyReferral>(ElderlyReferral.class);
        return util.exportExcel(list, "referral");
    }

    /**
     * 获取老人送诊
详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:referral:query')")
    @GetMapping(value = "/{erId}")
    public AjaxResult getInfo(@PathVariable("erId") Long erId)
    {
        return AjaxResult.success(elderlyReferralService.selectElderlyReferralById(erId));
    }

    /**
     * 新增老人送诊

     */
//    @PreAuthorize("@ss.hasPermi('system:referral:add')")
    @Log(title = "老人送诊", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElderlyReferral elderlyReferral)
    {
        return toAjax(elderlyReferralService.insertElderlyReferral(elderlyReferral));
    }

    /**
     * 修改老人送诊

     */
//    @PreAuthorize("@ss.hasPermi('system:referral:edit')")
    @Log(title = "老人送诊", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElderlyReferral elderlyReferral)
    {
        return toAjax(elderlyReferralService.updateElderlyReferral(elderlyReferral));
    }

    /**
     * 删除老人送诊

     */
//    @PreAuthorize("@ss.hasPermi('system:referral:remove')")
    @Log(title = "老人送诊", businessType = BusinessType.DELETE)
	@DeleteMapping("/{erIds}")
    public AjaxResult remove(@PathVariable Long[] erIds)
    {
        return toAjax(elderlyReferralService.deleteElderlyReferralByIds(erIds));
    }
}
